package com.itheima.mapper;

import com.itheima.pojo.Member;
import com.itheima.pojo.Order;
import com.itheima.pojo.OrderSetting;
import com.itheima.pojo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface OrderMapper {
    /**
     * 根据预约时间获取预约设置
     * @param orderDate
     * @return
     */
    @Select("select * from t_ordersetting where orderDate = #{orderDate}")
    OrderSetting findOrderSettingByOrderDate(Date orderDate);

    /**
     * 根据身份证获取会员信息
     * @param idCard
     * @return
     */
    @Select("select * from t_member where idCard = #{idCard}")
    Member findMemberByIdCard(String idCard);

    /**
     * 根据会员id、预约时间、套餐id查询预约信息
     * @param id
     * @param orderDate
     * @param setmealId
     * @return
     */
    @Select("select * from t_order where member_id = #{id} and orderDate = #{orderDate} and setmeal_id = #{setmealId}")
    Order findByMemberIdAndOrderDateAndSetmealId(Integer id, Date orderDate, Integer setmealId);

    @Insert("insert into t_order (member_id, orderDate, orderType, orderStatus, setmeal_id) " +
            "values(#{memberId},#{orderDate},#{orderType},#{orderStatus},#{setmealId})")
    void insert(Order order);

    /**
     * 获取预约套餐的统计数据
     * @return
     */
    @Select("select s.name,count(*) value from t_order o,t_setmeal s where o.setmeal_id=s.id group by o.setmeal_id order by value desc")
    List<SetmealVO> getReport();

    /**
     * 根据日期统计预约数量
     * @param date
     * @return
     */
    Integer findOrderCountByDate(Date date,String status);
}
